package compilator4urbi.compilator;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ResourceBundle;

import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import tom.library.emf.EcoreContainmentIntrospector;
import tom.library.sl.VisitFailure;
import behaviourdiagram.Actuator;
import behaviourdiagram.Behaviour;
import behaviourdiagram.Mission;
import behaviourdiagram.Sensor;
import compilator4urbi.Activator;
import compilator4urbi.util.BehaviourDiagramSerializer;

import java.util.List;
import java.util.ArrayList;


public class Compilator{ 

	private static boolean tom_equal_term_Mission(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_Mission(Object t) {return  t instanceof behaviourdiagram.Mission ;}private static boolean tom_equal_term_Sensor(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_Sensor(Object t) {return  t instanceof behaviourdiagram.Sensor ;}private static boolean tom_equal_term_char(char t1, char t2) {return  t1==t2 ;}private static boolean tom_is_sort_char(char t) {return  true ;} private static boolean tom_equal_term_String(String t1, String t2) {return  t1.equals(t2) ;}private static boolean tom_is_sort_String(String t) {return  t instanceof String ;} private static boolean tom_equal_term_BehaviourInput(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourInput(Object t) {return  t instanceof behaviourdiagram.BehaviourInput ;}private static boolean tom_equal_term_Behaviour(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_Behaviour(Object t) {return  t instanceof behaviourdiagram.Behaviour ;}private static boolean tom_equal_term_BehaviourState(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourState(Object t) {return  t instanceof behaviourdiagram.BehaviourState ;}private static boolean tom_equal_term_boolean(boolean t1, boolean t2) {return  t1==t2 ;}private static boolean tom_is_sort_boolean(boolean t) {return  true ;}   public static <O extends org.eclipse.emf.ecore.EObject> O constructBehaviourState(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                 private static boolean tom_equal_term_BehaviourInputEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourInputEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>)t).size()>0 && ((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>)t).get(0) instanceof behaviourdiagram.BehaviourInput)) ;}  private static <O> org.eclipse.emf.common.util.EList<O> appendBehaviourInputEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }   private static boolean tom_equal_term_BehaviourOutput(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourOutput(Object t) {return  t instanceof behaviourdiagram.BehaviourOutput ;}private static boolean tom_equal_term_Actuator(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_Actuator(Object t) {return  t instanceof behaviourdiagram.Actuator ;}private static boolean tom_equal_term_BehaviourOutputEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourOutputEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>)t).size()>0 && ((org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>)t).get(0) instanceof behaviourdiagram.BehaviourOutput)) ;}  private static <O> org.eclipse.emf.common.util.EList<O> appendBehaviourOutputEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }  private static boolean tom_is_fun_sym_Actuator( behaviourdiagram.Actuator  t) {return  t instanceof behaviourdiagram.Actuator ;}private static  String  tom_get_slot_Actuator_name( behaviourdiagram.Actuator  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("name")) ;}private static  String  tom_get_slot_Actuator_type( behaviourdiagram.Actuator  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("type")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>  tom_get_slot_Actuator_output( behaviourdiagram.Actuator  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>)t.eGet(t.eClass().getEStructuralFeature("output")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructActuator(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                   public static <O extends org.eclipse.emf.ecore.EObject> O constructBehaviourOutput(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                private static boolean tom_equal_term_int(int t1, int t2) {return  t1==t2 ;}private static boolean tom_is_sort_int(int t) {return  true ;} private static boolean tom_equal_term_FSM(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_FSM(Object t) {return  t instanceof fsm.FSM ;}private static boolean tom_equal_term_State(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_State(Object t) {return  t instanceof fsm.State ;}private static boolean tom_equal_term_Transition(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_Transition(Object t) {return  t instanceof fsm.Transition ;}private static boolean tom_is_fun_sym_Transition( fsm.Transition  t) {return  t instanceof fsm.Transition ;}private static  fsm.State  tom_get_slot_Transition_target( fsm.Transition  t) {return  (fsm.State)t.eGet(t.eClass().getEStructuralFeature("target")) ;}private static  String  tom_get_slot_Transition_condition( fsm.Transition  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("condition")) ;}private static  fsm.State  tom_get_slot_Transition_source( fsm.Transition  t) {return  (fsm.State)t.eGet(t.eClass().getEStructuralFeature("source")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructTransition(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                private static boolean tom_equal_term_TransitionEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_TransitionEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<fsm.Transition>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<fsm.Transition>)t).size()>0 && ((org.eclipse.emf.common.util.EList<fsm.Transition>)t).get(0) instanceof fsm.Transition)) ;}private static boolean tom_is_fun_sym_TransitionEList( org.eclipse.emf.common.util.EList<fsm.Transition>  t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (t.size() == 0 || (t.size()>0 && t.get(0) instanceof fsm.Transition)) ;}private static  org.eclipse.emf.common.util.EList<fsm.Transition>  tom_empty_array_TransitionEList(int n) { return  new org.eclipse.emf.common.util.BasicEList<fsm.Transition>(n) ;}private static  org.eclipse.emf.common.util.EList<fsm.Transition>  tom_cons_array_TransitionEList( fsm.Transition  e,  org.eclipse.emf.common.util.EList<fsm.Transition>  l) { return  appendTransitionEList(e,l) ;}private static  fsm.Transition  tom_get_element_TransitionEList_TransitionEList( org.eclipse.emf.common.util.EList<fsm.Transition>  l, int n) {return  l.get(n) ;}private static int tom_get_size_TransitionEList_TransitionEList( org.eclipse.emf.common.util.EList<fsm.Transition>  l) {return  l.size() ;}   private static   org.eclipse.emf.common.util.EList<fsm.Transition>  tom_get_slice_TransitionEList( org.eclipse.emf.common.util.EList<fsm.Transition>  subject, int begin, int end) {      org.eclipse.emf.common.util.EList<fsm.Transition>  result =  new org.eclipse.emf.common.util.BasicEList<fsm.Transition>(end-begin) ;     while(begin!=end) {       result =  appendTransitionEList( subject.get(begin) ,result) ;       begin++;     }     return result;   }    private static   org.eclipse.emf.common.util.EList<fsm.Transition>  tom_append_array_TransitionEList( org.eclipse.emf.common.util.EList<fsm.Transition>  l2,  org.eclipse.emf.common.util.EList<fsm.Transition>  l1) {     int size1 =  l1.size() ;     int size2 =  l2.size() ;     int index;      org.eclipse.emf.common.util.EList<fsm.Transition>  result =  new org.eclipse.emf.common.util.BasicEList<fsm.Transition>(size1+size2) ;     index=size1;     while(index >0) {       result =  appendTransitionEList( l1.get(size1-index) ,result) ;       index--;     }      index=size2;     while(index > 0) {       result =  appendTransitionEList( l2.get(size2-index) ,result) ;       index--;     }     return result;   }  private static <O> org.eclipse.emf.common.util.EList<O> appendTransitionEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }    private static boolean tom_is_fun_sym_State( fsm.State  t) {return  t instanceof fsm.State ;}private static  String  tom_get_slot_State_name( fsm.State  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("name")) ;}private static  String  tom_get_slot_State_code( fsm.State  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("code")) ;}private static  org.eclipse.emf.common.util.EList<fsm.Transition>  tom_get_slot_State_outgoing( fsm.State  t) {return  (org.eclipse.emf.common.util.EList<fsm.Transition>)t.eGet(t.eClass().getEStructuralFeature("outgoing")) ;}private static  org.eclipse.emf.common.util.EList<fsm.Transition>  tom_get_slot_State_incoming( fsm.State  t) {return  (org.eclipse.emf.common.util.EList<fsm.Transition>)t.eGet(t.eClass().getEStructuralFeature("incoming")) ;}private static  boolean  tom_get_slot_State_IsInitialState( fsm.State  t) {return  (java.lang.Boolean)t.eGet(t.eClass().getEStructuralFeature("IsInitialState")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructState(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                private static boolean tom_equal_term_StateEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_StateEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<fsm.State>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<fsm.State>)t).size()>0 && ((org.eclipse.emf.common.util.EList<fsm.State>)t).get(0) instanceof fsm.State)) ;}private static boolean tom_is_fun_sym_StateEList( org.eclipse.emf.common.util.EList<fsm.State>  t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (t.size() == 0 || (t.size()>0 && t.get(0) instanceof fsm.State)) ;}private static  org.eclipse.emf.common.util.EList<fsm.State>  tom_empty_array_StateEList(int n) { return  new org.eclipse.emf.common.util.BasicEList<fsm.State>(n) ;}private static  org.eclipse.emf.common.util.EList<fsm.State>  tom_cons_array_StateEList( fsm.State  e,  org.eclipse.emf.common.util.EList<fsm.State>  l) { return  appendStateEList(e,l) ;}private static  fsm.State  tom_get_element_StateEList_StateEList( org.eclipse.emf.common.util.EList<fsm.State>  l, int n) {return  l.get(n) ;}private static int tom_get_size_StateEList_StateEList( org.eclipse.emf.common.util.EList<fsm.State>  l) {return  l.size() ;}   private static   org.eclipse.emf.common.util.EList<fsm.State>  tom_get_slice_StateEList( org.eclipse.emf.common.util.EList<fsm.State>  subject, int begin, int end) {      org.eclipse.emf.common.util.EList<fsm.State>  result =  new org.eclipse.emf.common.util.BasicEList<fsm.State>(end-begin) ;     while(begin!=end) {       result =  appendStateEList( subject.get(begin) ,result) ;       begin++;     }     return result;   }    private static   org.eclipse.emf.common.util.EList<fsm.State>  tom_append_array_StateEList( org.eclipse.emf.common.util.EList<fsm.State>  l2,  org.eclipse.emf.common.util.EList<fsm.State>  l1) {     int size1 =  l1.size() ;     int size2 =  l2.size() ;     int index;      org.eclipse.emf.common.util.EList<fsm.State>  result =  new org.eclipse.emf.common.util.BasicEList<fsm.State>(size1+size2) ;     index=size1;     while(index >0) {       result =  appendStateEList( l1.get(size1-index) ,result) ;       index--;     }      index=size2;     while(index > 0) {       result =  appendStateEList( l2.get(size2-index) ,result) ;       index--;     }     return result;   }  private static <O> org.eclipse.emf.common.util.EList<O> appendStateEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }    private static boolean tom_is_fun_sym_FSM( fsm.FSM  t) {return  t instanceof fsm.FSM ;}private static  org.eclipse.emf.common.util.EList<fsm.State>  tom_get_slot_FSM_ownedStates( fsm.FSM  t) {return  (org.eclipse.emf.common.util.EList<fsm.State>)t.eGet(t.eClass().getEStructuralFeature("ownedStates")) ;}private static  org.eclipse.emf.common.util.EList<fsm.Transition>  tom_get_slot_FSM_ownedTransitions( fsm.FSM  t) {return  (org.eclipse.emf.common.util.EList<fsm.Transition>)t.eGet(t.eClass().getEStructuralFeature("ownedTransitions")) ;}private static  fsm.State  tom_get_slot_FSM_initialState( fsm.FSM  t) {return  (fsm.State)t.eGet(t.eClass().getEStructuralFeature("initialState")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructFSM(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                  private static boolean tom_is_fun_sym_Behaviour( behaviourdiagram.Behaviour  t) {return  t instanceof behaviourdiagram.Behaviour ;}private static  String  tom_get_slot_Behaviour_name( behaviourdiagram.Behaviour  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("name")) ;}private static  behaviourdiagram.BehaviourState  tom_get_slot_Behaviour_state( behaviourdiagram.Behaviour  t) {return  (behaviourdiagram.BehaviourState)t.eGet(t.eClass().getEStructuralFeature("state")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>  tom_get_slot_Behaviour_inputs( behaviourdiagram.Behaviour  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>)t.eGet(t.eClass().getEStructuralFeature("inputs")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>  tom_get_slot_Behaviour_outputs( behaviourdiagram.Behaviour  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourOutput>)t.eGet(t.eClass().getEStructuralFeature("outputs")) ;}private static  int  tom_get_slot_Behaviour_priority( behaviourdiagram.Behaviour  t) {return  (java.lang.Integer)t.eGet(t.eClass().getEStructuralFeature("priority")) ;}private static  fsm.FSM  tom_get_slot_Behaviour_representedBy( behaviourdiagram.Behaviour  t) {return  (fsm.FSM)t.eGet(t.eClass().getEStructuralFeature("representedBy")) ;}private static  String  tom_get_slot_Behaviour_inputCondition( behaviourdiagram.Behaviour  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("inputCondition")) ;}private static  String  tom_get_slot_Behaviour_outputCondition( behaviourdiagram.Behaviour  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("outputCondition")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructBehaviour(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                  public static <O extends org.eclipse.emf.ecore.EObject> O constructBehaviourInput(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                private static boolean tom_is_fun_sym_Sensor( behaviourdiagram.Sensor  t) {return  t instanceof behaviourdiagram.Sensor ;}private static  String  tom_get_slot_Sensor_name( behaviourdiagram.Sensor  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("name")) ;}private static  String  tom_get_slot_Sensor_type( behaviourdiagram.Sensor  t) {return  (java.lang.String)t.eGet(t.eClass().getEStructuralFeature("type")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>  tom_get_slot_Sensor_input( behaviourdiagram.Sensor  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.BehaviourInput>)t.eGet(t.eClass().getEStructuralFeature("input")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructSensor(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }                private static boolean tom_equal_term_SensorEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_SensorEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<behaviourdiagram.Sensor>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<behaviourdiagram.Sensor>)t).size()>0 && ((org.eclipse.emf.common.util.EList<behaviourdiagram.Sensor>)t).get(0) instanceof behaviourdiagram.Sensor)) ;}  private static <O> org.eclipse.emf.common.util.EList<O> appendSensorEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }   private static boolean tom_equal_term_BehaviourEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_BehaviourEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>)t).size()>0 && ((org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>)t).get(0) instanceof behaviourdiagram.Behaviour)) ;}private static boolean tom_is_fun_sym_BehaviourEList( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (t.size() == 0 || (t.size()>0 && t.get(0) instanceof behaviourdiagram.Behaviour)) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_empty_array_BehaviourEList(int n) { return  new org.eclipse.emf.common.util.BasicEList<behaviourdiagram.Behaviour>(n) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_cons_array_BehaviourEList( behaviourdiagram.Behaviour  e,  org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  l) { return  appendBehaviourEList(e,l) ;}private static  behaviourdiagram.Behaviour  tom_get_element_BehaviourEList_BehaviourEList( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  l, int n) {return  l.get(n) ;}private static int tom_get_size_BehaviourEList_BehaviourEList( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  l) {return  l.size() ;}   private static   org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_get_slice_BehaviourEList( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  subject, int begin, int end) {      org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  result =  new org.eclipse.emf.common.util.BasicEList<behaviourdiagram.Behaviour>(end-begin) ;     while(begin!=end) {       result =  appendBehaviourEList( subject.get(begin) ,result) ;       begin++;     }     return result;   }    private static   org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_append_array_BehaviourEList( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  l2,  org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  l1) {     int size1 =  l1.size() ;     int size2 =  l2.size() ;     int index;      org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  result =  new org.eclipse.emf.common.util.BasicEList<behaviourdiagram.Behaviour>(size1+size2) ;     index=size1;     while(index >0) {       result =  appendBehaviourEList( l1.get(size1-index) ,result) ;       index--;     }      index=size2;     while(index > 0) {       result =  appendBehaviourEList( l2.get(size2-index) ,result) ;       index--;     }     return result;   }  private static <O> org.eclipse.emf.common.util.EList<O> appendBehaviourEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }   private static boolean tom_equal_term_ActuatorEList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_ActuatorEList(Object t) {return  t instanceof org.eclipse.emf.common.util.EList<?> && (((org.eclipse.emf.common.util.EList<behaviourdiagram.Actuator>)t).size() == 0 || (((org.eclipse.emf.common.util.EList<behaviourdiagram.Actuator>)t).size()>0 && ((org.eclipse.emf.common.util.EList<behaviourdiagram.Actuator>)t).get(0) instanceof behaviourdiagram.Actuator)) ;}  private static <O> org.eclipse.emf.common.util.EList<O> appendActuatorEList(O e,org.eclipse.emf.common.util.EList<O> l) {   l.add(e);   return l; }  private static boolean tom_is_fun_sym_Mission( behaviourdiagram.Mission  t) {return  t instanceof behaviourdiagram.Mission ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.Sensor>  tom_get_slot_Mission_sensor( behaviourdiagram.Mission  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.Sensor>)t.eGet(t.eClass().getEStructuralFeature("sensor")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_get_slot_Mission_behaviours( behaviourdiagram.Mission  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>)t.eGet(t.eClass().getEStructuralFeature("behaviours")) ;}private static  org.eclipse.emf.common.util.EList<behaviourdiagram.Actuator>  tom_get_slot_Mission_actuator( behaviourdiagram.Mission  t) {return  (org.eclipse.emf.common.util.EList<behaviourdiagram.Actuator>)t.eGet(t.eClass().getEStructuralFeature("actuator")) ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructMission(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }  private static boolean tom_equal_term_FinalState(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_FinalState(Object t) {return  t instanceof fsm.FinalState ;}  public static <O extends org.eclipse.emf.ecore.EObject> O constructFinalState(O o, Object[] objs) {   int i=0;   EList<EStructuralFeature> sfes = o.eClass().getEAllStructuralFeatures();   for(EStructuralFeature esf : sfes) {     if(esf.isChangeable()) {       o.eSet(esf, objs[i]);       i++;     }   }   return o; }               private static boolean tom_equal_term_Strategy(Object t1, Object t2) {return  (t1.equals(t2)) ;}private static boolean tom_is_sort_Strategy(Object t) {return  (t instanceof tom.library.sl.Strategy) ;} private static boolean tom_equal_term_Position(Object t1, Object t2) {return  (t1.equals(t2)) ;}private static boolean tom_is_sort_Position(Object t) {return  (t instanceof tom.library.sl.Position) ;} private static  tom.library.sl.Strategy  tom_make_mu( tom.library.sl.Strategy  var,  tom.library.sl.Strategy  v) { return ( new tom.library.sl.Mu(var,v) );}private static  tom.library.sl.Strategy  tom_make_MuVar( String  name) { return ( new tom.library.sl.MuVar(name) );}private static  tom.library.sl.Strategy  tom_make_Identity() { return ( new tom.library.sl.Identity() );}private static  tom.library.sl.Strategy  tom_make_All( tom.library.sl.Strategy  v) { return ( new tom.library.sl.All(v) );}private static  tom.library.sl.Strategy  tom_make_Fail() { return ( new tom.library.sl.Fail() );}private static boolean tom_is_fun_sym_Sequence( tom.library.sl.Strategy  t) {return ( (t instanceof tom.library.sl.Sequence) );}private static  tom.library.sl.Strategy  tom_empty_list_Sequence() { return ( null );}private static  tom.library.sl.Strategy  tom_cons_list_Sequence( tom.library.sl.Strategy  head,  tom.library.sl.Strategy  tail) { return ( (tail==null)?head:new tom.library.sl.Sequence(head,tail) );}private static  tom.library.sl.Strategy  tom_get_head_Sequence_Strategy( tom.library.sl.Strategy  t) {return ( (tom.library.sl.Strategy)t.getChildAt(tom.library.sl.Sequence.FIRST) );}private static  tom.library.sl.Strategy  tom_get_tail_Sequence_Strategy( tom.library.sl.Strategy  t) {return ( (tom.library.sl.Strategy)t.getChildAt(tom.library.sl.Sequence.THEN) );}private static boolean tom_is_empty_Sequence_Strategy( tom.library.sl.Strategy  t) {return ( t == null );}   private static   tom.library.sl.Strategy  tom_append_list_Sequence( tom.library.sl.Strategy  l1,  tom.library.sl.Strategy  l2) {     if(( l1 == null )) {       return l2;     } else if(( l2 == null )) {       return l1;     } else if(( (l1 instanceof tom.library.sl.Sequence) )) {       if(( ( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.THEN) ) == null )) {         return ( (l2==null)?( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.FIRST) ):new tom.library.sl.Sequence(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.FIRST) ),l2) );       } else {         return ( (tom_append_list_Sequence(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.THEN) ),l2)==null)?( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.FIRST) ):new tom.library.sl.Sequence(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.FIRST) ),tom_append_list_Sequence(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Sequence.THEN) ),l2)) );       }     } else {       return ( (l2==null)?l1:new tom.library.sl.Sequence(l1,l2) );     }   }   private static   tom.library.sl.Strategy  tom_get_slice_Sequence( tom.library.sl.Strategy  begin,  tom.library.sl.Strategy  end, tom.library.sl.Strategy  tail) {     if( (begin.equals(end)) ) {       return tail;     } else if( (end.equals(tail))  && (( end == null ) ||  (end.equals(tom_empty_list_Sequence())) )) {       /* code to avoid a call to make, and thus to avoid looping during list-matching */       return begin;     }     return ( (( tom.library.sl.Strategy )tom_get_slice_Sequence(((( (begin instanceof tom.library.sl.Sequence) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Sequence.THEN) ):tom_empty_list_Sequence()),end,tail)==null)?((( (begin instanceof tom.library.sl.Sequence) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Sequence.FIRST) ):begin):new tom.library.sl.Sequence(((( (begin instanceof tom.library.sl.Sequence) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Sequence.FIRST) ):begin),( tom.library.sl.Strategy )tom_get_slice_Sequence(((( (begin instanceof tom.library.sl.Sequence) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Sequence.THEN) ):tom_empty_list_Sequence()),end,tail)) );   }   private static boolean tom_is_fun_sym_Choice( tom.library.sl.Strategy  t) {return ( (t instanceof tom.library.sl.Choice) );}private static  tom.library.sl.Strategy  tom_empty_list_Choice() { return ( null );}private static  tom.library.sl.Strategy  tom_cons_list_Choice( tom.library.sl.Strategy  head,  tom.library.sl.Strategy  tail) { return ( (tail==null)?head:new tom.library.sl.Choice(head,tail) );}private static  tom.library.sl.Strategy  tom_get_head_Choice_Strategy( tom.library.sl.Strategy  t) {return ( (tom.library.sl.Strategy)t.getChildAt(tom.library.sl.Choice.FIRST) );}private static  tom.library.sl.Strategy  tom_get_tail_Choice_Strategy( tom.library.sl.Strategy  t) {return ( (tom.library.sl.Strategy)t.getChildAt(tom.library.sl.Choice.THEN) );}private static boolean tom_is_empty_Choice_Strategy( tom.library.sl.Strategy  t) {return ( t ==null );}   private static   tom.library.sl.Strategy  tom_append_list_Choice( tom.library.sl.Strategy  l1,  tom.library.sl.Strategy  l2) {     if(( l1 ==null )) {       return l2;     } else if(( l2 ==null )) {       return l1;     } else if(( (l1 instanceof tom.library.sl.Choice) )) {       if(( ( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.THEN) ) ==null )) {         return ( (l2==null)?( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.FIRST) ):new tom.library.sl.Choice(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.FIRST) ),l2) );       } else {         return ( (tom_append_list_Choice(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.THEN) ),l2)==null)?( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.FIRST) ):new tom.library.sl.Choice(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.FIRST) ),tom_append_list_Choice(( (tom.library.sl.Strategy)l1.getChildAt(tom.library.sl.Choice.THEN) ),l2)) );       }     } else {       return ( (l2==null)?l1:new tom.library.sl.Choice(l1,l2) );     }   }   private static   tom.library.sl.Strategy  tom_get_slice_Choice( tom.library.sl.Strategy  begin,  tom.library.sl.Strategy  end, tom.library.sl.Strategy  tail) {     if( (begin.equals(end)) ) {       return tail;     } else if( (end.equals(tail))  && (( end ==null ) ||  (end.equals(tom_empty_list_Choice())) )) {       /* code to avoid a call to make, and thus to avoid looping during list-matching */       return begin;     }     return ( (( tom.library.sl.Strategy )tom_get_slice_Choice(((( (begin instanceof tom.library.sl.Choice) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Choice.THEN) ):tom_empty_list_Choice()),end,tail)==null)?((( (begin instanceof tom.library.sl.Choice) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Choice.FIRST) ):begin):new tom.library.sl.Choice(((( (begin instanceof tom.library.sl.Choice) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Choice.FIRST) ):begin),( tom.library.sl.Strategy )tom_get_slice_Choice(((( (begin instanceof tom.library.sl.Choice) ))?( (tom.library.sl.Strategy)begin.getChildAt(tom.library.sl.Choice.THEN) ):tom_empty_list_Choice()),end,tail)) );   }     private static  tom.library.sl.Strategy  tom_make_Try( tom.library.sl.Strategy  v) { return ( tom_cons_list_Choice(v,tom_cons_list_Choice(tom_make_Identity(),tom_empty_list_Choice())) );}private static  tom.library.sl.Strategy  tom_make_TopDown( tom.library.sl.Strategy  v) { return ( tom_make_mu(tom_make_MuVar("_x"),tom_cons_list_Sequence(v,tom_cons_list_Sequence(tom_make_All(tom_make_MuVar("_x")),tom_empty_list_Sequence()))) );}     public static org.w3c.dom.Node tom_mapping_buildAttribute(org.w3c.dom.Document dom,           String t0,             String v) {  org.w3c.dom.Attr res = dom.createAttribute(t0);   res.setValue(v);  return res; }   public static org.w3c.dom.Node tom_mapping_buildElement(org.w3c.dom.Document dom,         String name,          java.util.ArrayList<Node> attr,          java.util.ArrayList<Node> child) {   org.w3c.dom.Element res = dom.createElement(name);    for (Node n : child)   res.appendChild(n);   for (Node n : attr)   res.setAttribute(n.getNodeName(),n.getNodeValue());   return res; }  public static org.w3c.dom.Node tom_mapping_buildEntityReference(org.w3c.dom.Document dom,         String name,           java.util.ArrayList<Node> child) {   org.w3c.dom.EntityReference res = dom.createEntityReference(name);  for (Node n : child)   res.appendChild(n);   return res; }  public static java.util.ArrayList<Node> tom_mapping_buildTNodeList(org.w3c.dom.NodeList n) {  java.util.ArrayList<Node> res = new java.util.ArrayList<Node>();  for (int it=0;it<n.getLength();it++)   res.add(n.item(it));  return res; }  public static java.util.ArrayList<Node> tom_mapping_buildNamedNodeMap(org.w3c.dom.NamedNodeMap n) {  java.util.ArrayList<Node> res = new java.util.ArrayList<Node>();  String str_name;  int ins;  for (int it=0;it<n.getLength();it++) {   str_name = n.item(it).getNodeName();   ins = res.size();   for(int jt=0;jt<res.size();jt++) {    if (((org.w3c.dom.Attr)res.get(jt)).getNodeName().compareTo(str_name)>0) {     ins = jt;     break;    }   }   res.add(ins,n.item(it));  }    return res; }  public static java.util.ArrayList<Node> tom_mapping_add(Node e, java.util.ArrayList<Node> l) {  l.add(e);  return l; }  public static java.util.ArrayList<Node> tom_mapping_newTNodeList() {  return new java.util.ArrayList<Node>(); }  private static boolean tom_equal_term_TNode(Object t1, Object t2) {return t1.equals(t2);}private static boolean tom_is_sort_TNode(Object t) {return t instanceof org.w3c.dom.Node;}private static boolean tom_equal_term_TDocument(Object t1, Object t2) {return t1.equals(t2);}private static boolean tom_is_sort_TDocument(Object t) {return t instanceof org.w3c.dom.Document;}private static boolean tom_equal_term_TNodeList(Object l1, Object l2) {return  l1.equals(l2) ;}private static boolean tom_is_sort_TNodeList(Object t) {return  t instanceof java.util.ArrayList ;}private static boolean tom_is_fun_sym_concTNode( java.util.ArrayList<Node>  t) {return  (t!= null) ;}private static  java.util.ArrayList<Node>  tom_empty_array_concTNode(int n) { return  new java.util.ArrayList<Node>(n) ;}private static  java.util.ArrayList<Node>  tom_cons_array_concTNode(org.w3c.dom.Node e,  java.util.ArrayList<Node>  l) { return  tom_mapping_add(e,l)  ;}private static org.w3c.dom.Node tom_get_element_concTNode_TNodeList( java.util.ArrayList<Node>  l, int n) {return  (org.w3c.dom.Node)l.get(n) ;}private static int tom_get_size_concTNode_TNodeList( java.util.ArrayList<Node>  l) {return  l.size() ;}   private static   java.util.ArrayList<Node>  tom_get_slice_concTNode( java.util.ArrayList<Node>  subject, int begin, int end) {      java.util.ArrayList<Node>  result =  new java.util.ArrayList<Node>(end-begin) ;     while(begin!=end) {       result =  tom_mapping_add( (org.w3c.dom.Node)subject.get(begin) ,result)  ;       begin++;     }     return result;   }    private static   java.util.ArrayList<Node>  tom_append_array_concTNode( java.util.ArrayList<Node>  l2,  java.util.ArrayList<Node>  l1) {     int size1 =  l1.size() ;     int size2 =  l2.size() ;     int index;      java.util.ArrayList<Node>  result =  new java.util.ArrayList<Node>(size1+size2) ;     index=size1;     while(index >0) {       result =  tom_mapping_add( (org.w3c.dom.Node)l1.get(size1-index) ,result)  ;       index--;     }      index=size2;     while(index > 0) {       result =  tom_mapping_add( (org.w3c.dom.Node)l2.get(size2-index) ,result)  ;       index--;     }     return result;   }private static boolean tom_is_fun_sym_ElementNode(org.w3c.dom.Node t) {return  (t!= null) && (t.getNodeType()==org.w3c.dom.Node.ELEMENT_NODE);}private static org.w3c.dom.Document tom_get_slot_ElementNode_Doc(org.w3c.dom.Node t) {return  ((org.w3c.dom.Element)t).getOwnerDocument();}private static  String  tom_get_slot_ElementNode_Name(org.w3c.dom.Node t) {return  ((org.w3c.dom.Element)t).getNodeName();}private static  java.util.ArrayList<Node>  tom_get_slot_ElementNode_AttrList(org.w3c.dom.Node t) {return  tom_mapping_buildNamedNodeMap(((org.w3c.dom.Element)t).getAttributes());}private static  java.util.ArrayList<Node>  tom_get_slot_ElementNode_ChildList(org.w3c.dom.Node t) {return  tom_mapping_buildTNodeList(((org.w3c.dom.Element)t).getChildNodes());}private static boolean tom_is_fun_sym_AttributeNode(org.w3c.dom.Node t) {return  (t!= null) && (t.getNodeType()==org.w3c.dom.Node.ATTRIBUTE_NODE);}private static org.w3c.dom.Document tom_get_slot_AttributeNode_Doc(org.w3c.dom.Node t) {return  ((org.w3c.dom.Attr)t).getOwnerDocument();}private static  String  tom_get_slot_AttributeNode_Name(org.w3c.dom.Node t) {return  ((org.w3c.dom.Attr)t).getName();}private static  String  tom_get_slot_AttributeNode_Specified(org.w3c.dom.Node t) {return  (((org.w3c.dom.Attr)t).getSpecified()?"true":"false") ;}private static  String  tom_get_slot_AttributeNode_Value(org.w3c.dom.Node t) {return  ((org.w3c.dom.Attr)t).getValue() ;}  public static class generateUrbiCode extends tom.library.sl.AbstractStrategyBasic {public generateUrbiCode() {super(tom_make_Fail());}public tom.library.sl.Visitable[] getChildren() {tom.library.sl.Visitable[] stratChilds = new tom.library.sl.Visitable[getChildCount()];stratChilds[0] = super.getChildAt(0);return stratChilds;}public tom.library.sl.Visitable setChildren(tom.library.sl.Visitable[] children) {super.setChildAt(0, children[0]);return this;}public int getChildCount() {return 1;}public tom.library.sl.Visitable getChildAt(int index) {switch (index) {case 0: return super.getChildAt(0);default: throw new IndexOutOfBoundsException();}}public tom.library.sl.Visitable setChildAt(int index, tom.library.sl.Visitable child) {switch (index) {case 0: return super.setChildAt(0, child);default: throw new IndexOutOfBoundsException();}}@SuppressWarnings("unchecked")public  behaviourdiagram.Sensor  visit_Sensor( behaviourdiagram.Sensor  tom__arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {{{if (tom_is_sort_Sensor(tom__arg)) {if (tom_is_fun_sym_Sensor((( behaviourdiagram.Sensor )tom__arg))) { String  tom_name=tom_get_slot_Sensor_name((( behaviourdiagram.Sensor )tom__arg));







 
	    	  
	         String sensorC = resourceBundle.getString("get.sensorContent");
             sensorC = sensorC.replace("{name}", tom_name);
             String typeSensor = getTypeSensors(getElementRacineFileMapping(fileMapping), tom_name);  
             sensorC = sensorC.replace("{type}", typeSensor);
             String sensorConcrete = sensorConcreteName(fileMapping, tom_name);
             sensorC = sensorC.replace("{concreteSensor}", sensorConcrete);
	         sensorOutput.println(sensorC);
	         sensorTest += tom_name+ " = \"+ Global."+tom_name+".val +\" ,"; 
	      }}}}return _visit_Sensor(tom__arg,introspector); }@SuppressWarnings("unchecked")public  behaviourdiagram.Actuator  visit_Actuator( behaviourdiagram.Actuator  tom__arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {{{if (tom_is_sort_Actuator(tom__arg)) {if (tom_is_fun_sym_Actuator((( behaviourdiagram.Actuator )tom__arg))) { String  tom_name=tom_get_slot_Actuator_name((( behaviourdiagram.Actuator )tom__arg));




             String actuatorC = resourceBundle.getString("get.actuatorContent");
                 actuatorC = actuatorC.replace("{name}", tom_name);
                 String typeAct = getTypeActuators(getElementRacineFileMapping(fileMapping), tom_name);
                 actuatorC = actuatorC.replace("{type}", typeAct);
                 String act = actuatorConcreteName(fileMapping, tom_name);
                 actuatorC = actuatorC.replace("{concreteActuator}", act);
                 actuatorOutput.println(actuatorC);
           }}}}return _visit_Actuator(tom__arg,introspector); }@SuppressWarnings("unchecked")public  behaviourdiagram.Behaviour  visit_Behaviour( behaviourdiagram.Behaviour  tom__arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {{{if (tom_is_sort_Behaviour(tom__arg)) {if (tom_is_fun_sym_Behaviour((( behaviourdiagram.Behaviour )tom__arg))) { fsm.FSM  tomMatch3NameNumber_freshVar_6=tom_get_slot_Behaviour_representedBy((( behaviourdiagram.Behaviour )tom__arg)); String  tom_nameBehaviour=tom_get_slot_Behaviour_name((( behaviourdiagram.Behaviour )tom__arg));if (tom_is_fun_sym_FSM(tomMatch3NameNumber_freshVar_6)) { org.eclipse.emf.common.util.EList<fsm.State>  tom_state=tom_get_slot_FSM_ownedStates(tomMatch3NameNumber_freshVar_6); org.eclipse.emf.common.util.EList<fsm.Transition>  tom_transition=tom_get_slot_FSM_ownedTransitions(tomMatch3NameNumber_freshVar_6); fsm.State  tom_initialState=tom_get_slot_FSM_initialState(tomMatch3NameNumber_freshVar_6);




              try{
                String pathName = path + File.separator + resourceBundle.getString("get.nameBehaviourFile").replace("{nameBehaviour}", tom_nameBehaviour); 
                FileWriter fileBehaviour = new FileWriter(pathName);
                PrintWriter behaviourOutput = new PrintWriter(fileBehaviour);
                loadFile += resourceBundle.getString("loadFile").replace("{path}", pathName).replace("\\", "\\\\") + "\n";
                behaviourOutput.println(resourceBundle.getString("get.behaviourHeader").replace("{nameBehaviour}", tom_nameBehaviour) + "\n"); 
                String initState = resourceBundle.getString("get.fsmStateContent");                
                initState = initState.replace("{nameBehaviour}", tom_nameBehaviour);
                initState = initState.replace("{nameState}", tom_initialState.getName());

                String code = tom_initialState.getCode();
                code = replaceString(code, nameActuatorList, "speed");
                code = replaceString(code, nameSensorList, "val");
                if ( tom_initialState
instanceof fsm.FinalState)
                    {
                    	 String codeFinalState=resourceBundle.getString("get.codeFinalState");
                    	 codeFinalState = codeFinalState.replace("{nameBehaviour}",tom_nameBehaviour);
                    	 codeFinalState = codeFinalState.replace("{initialStateName}",tom_initialState.getName());
                    	 code += "\n" + codeFinalState + "\n"; 
                     }

                initState = initState.replace("{code}", code);
                initState = initState.replace("{bool}", "true");
                initState = initState.replace("{i0}", "1");
                behaviourOutput.println(initState + "\n"); 

               int j = 1;
                         
               {{if (tom_is_sort_StateEList(tom_state)) {if (tom_is_fun_sym_StateEList((( org.eclipse.emf.common.util.EList<fsm.State> )tom_state))) {int tomMatch4NameNumber_end_5=0;do {{if (!(tomMatch4NameNumber_end_5 >= tom_get_size_StateEList_StateEList((( org.eclipse.emf.common.util.EList<fsm.State> )tom_state)))) { fsm.State  tom_etat=tom_get_element_StateEList_StateEList((( org.eclipse.emf.common.util.EList<fsm.State> )tom_state),tomMatch4NameNumber_end_5);

                  if (!tom_etat.equals(tom_initialState)){
                	 
                	 String state = resourceBundle.getString("get.fsmStateContent");                
                     state = state.replace("{nameBehaviour}", tom_nameBehaviour);
                     state = state.replace("{nameState}", tom_etat.getName());

                     code = tom_etat.getCode();
                     code = replaceString(code, nameActuatorList, "speed");
                     code = replaceString(code, nameSensorList, "val");
                     if ( tom_etat
instanceof fsm.FinalState)
                     {
                    	 String codeFinalState=resourceBundle.getString("get.codeFinalState");
                    	 codeFinalState = codeFinalState.replace("{nameBehaviour}",tom_nameBehaviour);
                    	 codeFinalState = codeFinalState.replace("{initialStateName}",tom_initialState.getName());
                    	 code += "\n" + codeFinalState + "\n"; 
                     }

                	 state = state.replace("{code}", code);
                     state = state.replace("{bool}", "false");
                     state = state.replace("{i0}", ""+ ++j);
                     behaviourOutput.println(state + "\n"); 
                    
                    
                     }
                  }tomMatch4NameNumber_end_5=tomMatch4NameNumber_end_5 + 1;}} while(!(tomMatch4NameNumber_end_5 > tom_get_size_StateEList_StateEList((( org.eclipse.emf.common.util.EList<fsm.State> )tom_state))));}}}}
     
               


                behaviourOutput.println(resourceBundle.getString("get.fsmTransitionComment"));
                int i = 1;
                {{if (tom_is_sort_TransitionEList(tom_transition)) {if (tom_is_fun_sym_TransitionEList((( org.eclipse.emf.common.util.EList<fsm.Transition> )tom_transition))) {int tomMatch5NameNumber_end_5=0;do {{if (!(tomMatch5NameNumber_end_5 >= tom_get_size_TransitionEList_TransitionEList((( org.eclipse.emf.common.util.EList<fsm.Transition> )tom_transition)))) { fsm.Transition  tomMatch5NameNumber_freshVar_11=tom_get_element_TransitionEList_TransitionEList((( org.eclipse.emf.common.util.EList<fsm.Transition> )tom_transition),tomMatch5NameNumber_end_5);if (tom_is_fun_sym_Transition(tomMatch5NameNumber_freshVar_11)) { fsm.State  tomMatch5NameNumber_freshVar_8=tom_get_slot_Transition_target(tomMatch5NameNumber_freshVar_11); fsm.State  tomMatch5NameNumber_freshVar_10=tom_get_slot_Transition_source(tomMatch5NameNumber_freshVar_11);if (tom_is_fun_sym_State(tomMatch5NameNumber_freshVar_8)) {if (tom_is_fun_sym_State(tomMatch5NameNumber_freshVar_10)) {

                     String transition = resourceBundle.getString("get.fsmTransitionContent");
                     transition = transition.replace("{nameBehaviour}", tom_nameBehaviour);
                     transition = transition.replace("{source}", tom_get_slot_State_name(tomMatch5NameNumber_freshVar_10));
                     transition = transition.replace("{target}", tom_get_slot_State_name(tomMatch5NameNumber_freshVar_8));
                     String cond = replaceString(tom_get_slot_Transition_condition(tomMatch5NameNumber_freshVar_11), nameSensorList, "val");
                     transition = transition.replace("{condition}", cond);
                     transition = transition.replace("{i0}", "" + i++);
                     behaviourOutput.println(transition);
                  }}}}tomMatch5NameNumber_end_5=tomMatch5NameNumber_end_5 + 1;}} while(!(tomMatch5NameNumber_end_5 > tom_get_size_TransitionEList_TransitionEList((( org.eclipse.emf.common.util.EList<fsm.Transition> )tom_transition))));}}}}
 

				String endFile = resourceBundle.getString("get.behaviourEndFile");
				endFile = endFile.replace("{nameBehaviour}", tom_nameBehaviour);
                behaviourOutput.println("\n\n" + endFile);

                //G�n�re les codes pour les tests
                if(generateTestCode){
                    String testCode = resourceBundle.getString("get.testCode");
                    testCode = testCode.replace("{fileName}", path + File.separator + "urbi_log2.txt");
                    testCode = testCode.replace("{sensorTest}", sensorTest);
                    behaviourOutput.println("\n\n //Code Test\n" + testCode );
                }
 
                behaviourOutput.close();
              } catch (IOException e) {
	             e.printStackTrace();
              } 
           }}}}}return _visit_Behaviour(tom__arg,introspector); }@SuppressWarnings("unchecked")public  behaviourdiagram.Sensor  _visit_Sensor( behaviourdiagram.Sensor  arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {if (!((environment ==  null ))) {return (( behaviourdiagram.Sensor )any.visit(environment,introspector));} else {return any.visitLight(arg,introspector);} }@SuppressWarnings("unchecked")public  behaviourdiagram.Actuator  _visit_Actuator( behaviourdiagram.Actuator  arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {if (!((environment ==  null ))) {return (( behaviourdiagram.Actuator )any.visit(environment,introspector));} else {return any.visitLight(arg,introspector);} }@SuppressWarnings("unchecked")public  behaviourdiagram.Behaviour  _visit_Behaviour( behaviourdiagram.Behaviour  arg, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {if (!((environment ==  null ))) {return (( behaviourdiagram.Behaviour )any.visit(environment,introspector));} else {return any.visitLight(arg,introspector);} }@SuppressWarnings("unchecked")public <T> T visitLight(T v, tom.library.sl.Introspector introspector) throws tom.library.sl.VisitFailure {if (tom_is_sort_Sensor(v)) {return ((T)visit_Sensor((( behaviourdiagram.Sensor )v),introspector));}if (tom_is_sort_Actuator(v)) {return ((T)visit_Actuator((( behaviourdiagram.Actuator )v),introspector));}if (tom_is_sort_Behaviour(v)) {return ((T)visit_Behaviour((( behaviourdiagram.Behaviour )v),introspector));}if (!((environment ==  null ))) {return ((T)any.visit(environment,introspector));} else {return any.visitLight(v,introspector);} }}private static  tom.library.sl.Strategy  tom_make_generateUrbiCode() { return new generateUrbiCode();}


   
    static String loadFile = "";
    static String path = "";
    static ResourceBundle resourceBundle = ResourceBundle.getBundle("compilator4urbi.conf.generateUrbiCode");
    static FileWriter fileSensor = null; 
    static PrintWriter sensorOutput = null;
    static FileWriter fileActuator = null; 
    static PrintWriter actuatorOutput = null;
    static String fileMapping = null;
    static boolean generateTestCode = false;
    static String sensorTest = "";
    static List<String> nameSensorList;
    static List<String> nameActuatorList;
           

    public static void  main(String[] args) throws VisitFailure { 
       File filename = new File("D:/Nouveau dossier/document/Master/Gestion de Projet/Test_4/Test_4/SearchForLight.uge.xmi");
       Mission mission = BehaviourDiagramSerializer.load(filename);
       generateUrbiCode(mission, filename, true);
       
    }
   

    public static void init(String path){ 
       try{
           String pathName = path + File.separator + resourceBundle.getString("get.nameSensorFile");
           fileSensor = new FileWriter(pathName);
           sensorOutput = new PrintWriter(fileSensor);
           
           loadFile = resourceBundle.getString("loadFile").replace("{path}", pathName).replace("\\", "\\\\") + "\n";

           pathName = path + File.separator + resourceBundle.getString("get.nameActuatorFile");
           fileActuator = new FileWriter(pathName);
           actuatorOutput = new PrintWriter(fileActuator);
           loadFile += resourceBundle.getString("loadFile").replace("{path}", pathName).replace("\\", "\\\\") + "\n";
           
        } catch (IOException e) {
	       e.printStackTrace();
        }
     }


public static void generateArbiterCode(Mission mission, String path) {
	   {{if (tom_is_sort_Mission(mission)) {if (tom_is_fun_sym_Mission((( behaviourdiagram.Mission )mission))) { org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour>  tom_behaviours=tom_get_slot_Mission_behaviours((( behaviourdiagram.Mission )mission));
 try {
	      FileWriter file = new FileWriter(path + File.separator + resourceBundle.getString("get.nameArbitreFile")); 
             PrintWriter output = new PrintWriter(file);
            
             String fsm_u = resourceBundle.getString("loadFile").replace("{path}", path + File.separator + "fsm.u");
             fsm_u = fsm_u.replace("\\", "\\\\");
             output.println(fsm_u + "\n\n");
             output.println(loadFile);
            
             String fsm = "";
             String active = "";
             String freeze = "";
             String functionCond = "";
             String event="";
             String ats="";
           
             {{if (tom_is_sort_BehaviourEList(tom_behaviours)) {if (tom_is_fun_sym_BehaviourEList((( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour> )tom_behaviours))) {int tomMatch7NameNumber_end_5=0;do {{if (!(tomMatch7NameNumber_end_5 >= tom_get_size_BehaviourEList_BehaviourEList((( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour> )tom_behaviours)))) { behaviourdiagram.Behaviour  tomMatch7NameNumber_freshVar_16=tom_get_element_BehaviourEList_BehaviourEList((( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour> )tom_behaviours),tomMatch7NameNumber_end_5);if (tom_is_fun_sym_Behaviour(tomMatch7NameNumber_freshVar_16)) { String  tom_name=tom_get_slot_Behaviour_name(tomMatch7NameNumber_freshVar_16);if (tom_is_fun_sym_FSM(tom_get_slot_Behaviour_representedBy(tomMatch7NameNumber_freshVar_16))) {


 
                  String input_cond = replaceString(tom_get_slot_Behaviour_inputCondition(tomMatch7NameNumber_freshVar_16), nameSensorList, "val");
                  String output_cond = replaceString(tom_get_slot_Behaviour_outputCondition(tomMatch7NameNumber_freshVar_16), nameSensorList, "val");
                  fsm += "var fsm_"+tom_name+" = Tag.new|;\n";
                  active += "var active_fsm_"+tom_name+" = false|;\n";
                  event+="var Global.stop_fsm_"+tom_name+"_event = Event.new|;\n";
                  freeze += "fsm_"+tom_name+" :\n _root_"+tom_name+"_.enter(),\nfsm_"+tom_name+".freeze();\n\n";
                  functionCond += "function cond_"+tom_name+"()\n{\n" + input_cond+ "\n}|;\n\n";
                  functionCond += "function cond_quit_"+tom_name+"()\n{\n"  + output_cond+"\n}|;\n\n";
                  ats+="at (";
                 
                  for (Behaviour bh : tom_behaviours){
                	  if (tom_get_slot_Behaviour_priority(tomMatch7NameNumber_freshVar_16)< bh.getPriority() )
                		  ats+="not active_fsm_"+bh.getName()+" and not cond_"+bh.getName()+ " and ";  
                  }
                  ats+="not active_fsm_"+tom_name+" and ";
                  ats+="cond_"+tom_name+")\n{\n  ";
                  ats+="activeFSMChan << \"fsm_"+tom_name+"\" |\n";
                  for (Behaviour bh : tom_behaviours){
                	  if ( bh.getName().compareTo(tom_name)==0)
                		  ats+=" fsm_"+tom_name+ ".unfreeze() | active_fsm_"+tom_name+" = true |\n";
                	  else
                		  ats+=" fsm_"+bh.getName()+ ".freeze() | active_fsm_"+bh.getName()+" = false |\n";
                		    
                  }
                  ats+=";\n};\n\n";
                  ats+="at (";
                  ats+="cond_quit_"+tom_name+ " and active_fsm_"+tom_name+")\n";
                  ats+="{\n";
                  ats+=" fsm_"+tom_name+".freeze() | active_fsm_"+tom_name+" = false;";
                  ats+="\n};\n\n";
                  ats+="at (";
                  ats+=" stop_fsm_"+tom_name+ "_event?)\n";
                  ats+="{\n";
                  ats+="fsm_"+tom_name+".freeze() | active_fsm_"+tom_name+" = false;";
                  ats+="\n};\n\n";             
                }}}tomMatch7NameNumber_end_5=tomMatch7NameNumber_end_5 + 1;}} while(!(tomMatch7NameNumber_end_5 > tom_get_size_BehaviourEList_BehaviourEList((( org.eclipse.emf.common.util.EList<behaviourdiagram.Behaviour> )tom_behaviours))));}}}}
       
             output.println(fsm + "\n" + active + "\n" +event +"\n"+"var activeFSMChan= Channel.new(\"activeFSM\")|;"+"\n\n"+ freeze +"\n" + functionCond+"\n"+ats);
             output.close();

	      	}
            catch (IOException e) {
	         e.printStackTrace();
          }

}}}}}


    public static void generateUrbiCode(Mission mission, File filename, boolean generateTest) throws VisitFailure{
	   
        fileMapping = filename + "map";
        path = filename.getParent();
        generateTestCode = generateTest;
        System.out.println("Genere les codes urbi !!!");
        System.out.println("***************************************************");
       
        init(path);
        nameActuatorList = getListActuatorName(mission);
        nameSensorList = getListSensorName(mission);
       tom_make_TopDown(tom_make_Try(tom_make_generateUrbiCode())).visitLight(mission, new EcoreContainmentIntrospector());
        
        sensorOutput.close(); 
        actuatorOutput.close(); 
        generateArbiterCode (mission, path);
       
       
        copyFileFSM(path);
        System.out.println("Tous les fichiers urbi ont ete generes avec succes"); 
        
    }


    
    static Document dom;

    /**
	m�thode faisant le mapping entre sensors abstraits et concrets
	
     **/
    public static String sensorConcreteName(String filename, String nameAbstractSensor){
    	String resultName = "";
    	try {
    		dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
    		Element elementRacine = dom.getDocumentElement();
    		resultName = mapSensors(elementRacine,  nameAbstractSensor);
    	   	return resultName;
        } catch (Exception e){
    		System.out.println("Fichier de mapping introuvable: Sensor " + nameAbstractSensor);
    		return "";
    	}
    }

    private static String mapSensors(Node n, String name){
        String result = "";
    	{{if (tom_is_sort_TNode(n)) {if (tom_is_fun_sym_ElementNode(((org.w3c.dom.Node)n))) { java.util.ArrayList<Node>  tomMatch8NameNumber_freshVar_3=tom_get_slot_ElementNode_ChildList(((org.w3c.dom.Node)n));if (tom_is_fun_sym_concTNode(tom_get_slot_ElementNode_AttrList(((org.w3c.dom.Node)n)))) {if (tom_is_fun_sym_concTNode(tomMatch8NameNumber_freshVar_3)) {int tomMatch8NameNumber_end_12=0;do {{if (!(tomMatch8NameNumber_end_12 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_3))) {org.w3c.dom.Node tomMatch8NameNumber_freshVar_18=tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_3,tomMatch8NameNumber_end_12);if (tom_is_fun_sym_ElementNode(tomMatch8NameNumber_freshVar_18)) { java.util.ArrayList<Node>  tomMatch8NameNumber_freshVar_16=tom_get_slot_ElementNode_AttrList(tomMatch8NameNumber_freshVar_18); java.util.ArrayList<Node>  tomMatch8NameNumber_freshVar_17=tom_get_slot_ElementNode_ChildList(tomMatch8NameNumber_freshVar_18);if (tom_equal_term_String("sensorDec", tom_get_slot_ElementNode_Name(tomMatch8NameNumber_freshVar_18))) {if (tom_is_fun_sym_concTNode(tomMatch8NameNumber_freshVar_16)) {int tomMatch8NameNumber_end_24=0;do {{if (!(tomMatch8NameNumber_end_24 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_16))) {org.w3c.dom.Node tomMatch8NameNumber_freshVar_37=tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_16,tomMatch8NameNumber_end_24);if (tom_is_fun_sym_AttributeNode(tomMatch8NameNumber_freshVar_37)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch8NameNumber_freshVar_37))) {if (tom_is_fun_sym_concTNode(tomMatch8NameNumber_freshVar_17)) {int tomMatch8NameNumber_end_31=0;do {{if (!(tomMatch8NameNumber_end_31 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_17))) {org.w3c.dom.Node tomMatch8NameNumber_freshVar_42=tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_17,tomMatch8NameNumber_end_31);if (tom_is_fun_sym_ElementNode(tomMatch8NameNumber_freshVar_42)) { java.util.ArrayList<Node>  tomMatch8NameNumber_freshVar_40=tom_get_slot_ElementNode_AttrList(tomMatch8NameNumber_freshVar_42); java.util.ArrayList<Node>  tomMatch8NameNumber_freshVar_41=tom_get_slot_ElementNode_ChildList(tomMatch8NameNumber_freshVar_42);if (tom_equal_term_String("sensorMap", tom_get_slot_ElementNode_Name(tomMatch8NameNumber_freshVar_42))) {if (tom_is_fun_sym_concTNode(tomMatch8NameNumber_freshVar_40)) {int tomMatch8NameNumber_end_48=0;do {{if (!(tomMatch8NameNumber_end_48 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch8NameNumber_freshVar_60=tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40,tomMatch8NameNumber_end_48);if (tom_is_fun_sym_AttributeNode(tomMatch8NameNumber_freshVar_60)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch8NameNumber_freshVar_60))) {int tomMatch8NameNumber_end_52=tomMatch8NameNumber_end_48 + 1;do {{if (!(tomMatch8NameNumber_end_52 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch8NameNumber_freshVar_65=tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40,tomMatch8NameNumber_end_52);if (tom_is_fun_sym_AttributeNode(tomMatch8NameNumber_freshVar_65)) {if (tom_equal_term_String("Type", tom_get_slot_AttributeNode_Name(tomMatch8NameNumber_freshVar_65))) {if (tom_is_fun_sym_concTNode(tomMatch8NameNumber_freshVar_41)) {if (0 >= tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_41)) {

if (tom_get_slot_AttributeNode_Value(tomMatch8NameNumber_freshVar_37).compareTo(name)==0){result=tom_get_slot_AttributeNode_Value(tomMatch8NameNumber_freshVar_60);}else {mapSensors(tom_get_element_concTNode_TNodeList(tomMatch8NameNumber_freshVar_3,tomMatch8NameNumber_end_12).getNextSibling(), name);}}}}}}tomMatch8NameNumber_end_52=tomMatch8NameNumber_end_52 + 1;}} while(!(tomMatch8NameNumber_end_52 > tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40)));}}}tomMatch8NameNumber_end_48=tomMatch8NameNumber_end_48 + 1;}} while(!(tomMatch8NameNumber_end_48 > tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_40)));}}}}tomMatch8NameNumber_end_31=tomMatch8NameNumber_end_31 + 1;}} while(!(tomMatch8NameNumber_end_31 > tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_17)));}}}}tomMatch8NameNumber_end_24=tomMatch8NameNumber_end_24 + 1;}} while(!(tomMatch8NameNumber_end_24 > tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_16)));}}}}tomMatch8NameNumber_end_12=tomMatch8NameNumber_end_12 + 1;}} while(!(tomMatch8NameNumber_end_12 > tom_get_size_concTNode_TNodeList(tomMatch8NameNumber_freshVar_3)));}}}}}}

    	return result;
    }

    private static String getTypeSensors(Node n, String name){
        if (n == null) return "";
    	String result = "";
    	{{if (tom_is_sort_TNode(n)) {if (tom_is_fun_sym_ElementNode(((org.w3c.dom.Node)n))) { java.util.ArrayList<Node>  tomMatch9NameNumber_freshVar_3=tom_get_slot_ElementNode_ChildList(((org.w3c.dom.Node)n));if (tom_is_fun_sym_concTNode(tom_get_slot_ElementNode_AttrList(((org.w3c.dom.Node)n)))) {if (tom_is_fun_sym_concTNode(tomMatch9NameNumber_freshVar_3)) {int tomMatch9NameNumber_end_12=0;do {{if (!(tomMatch9NameNumber_end_12 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_3))) {org.w3c.dom.Node tomMatch9NameNumber_freshVar_18=tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_3,tomMatch9NameNumber_end_12);if (tom_is_fun_sym_ElementNode(tomMatch9NameNumber_freshVar_18)) { java.util.ArrayList<Node>  tomMatch9NameNumber_freshVar_16=tom_get_slot_ElementNode_AttrList(tomMatch9NameNumber_freshVar_18); java.util.ArrayList<Node>  tomMatch9NameNumber_freshVar_17=tom_get_slot_ElementNode_ChildList(tomMatch9NameNumber_freshVar_18);if (tom_equal_term_String("sensorDec", tom_get_slot_ElementNode_Name(tomMatch9NameNumber_freshVar_18))) {if (tom_is_fun_sym_concTNode(tomMatch9NameNumber_freshVar_16)) {int tomMatch9NameNumber_end_24=0;do {{if (!(tomMatch9NameNumber_end_24 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_16))) {org.w3c.dom.Node tomMatch9NameNumber_freshVar_37=tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_16,tomMatch9NameNumber_end_24);if (tom_is_fun_sym_AttributeNode(tomMatch9NameNumber_freshVar_37)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch9NameNumber_freshVar_37))) {if (tom_is_fun_sym_concTNode(tomMatch9NameNumber_freshVar_17)) {int tomMatch9NameNumber_end_31=0;do {{if (!(tomMatch9NameNumber_end_31 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_17))) {org.w3c.dom.Node tomMatch9NameNumber_freshVar_42=tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_17,tomMatch9NameNumber_end_31);if (tom_is_fun_sym_ElementNode(tomMatch9NameNumber_freshVar_42)) { java.util.ArrayList<Node>  tomMatch9NameNumber_freshVar_40=tom_get_slot_ElementNode_AttrList(tomMatch9NameNumber_freshVar_42); java.util.ArrayList<Node>  tomMatch9NameNumber_freshVar_41=tom_get_slot_ElementNode_ChildList(tomMatch9NameNumber_freshVar_42);if (tom_equal_term_String("sensorMap", tom_get_slot_ElementNode_Name(tomMatch9NameNumber_freshVar_42))) {if (tom_is_fun_sym_concTNode(tomMatch9NameNumber_freshVar_40)) {int tomMatch9NameNumber_end_48=0;do {{if (!(tomMatch9NameNumber_end_48 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch9NameNumber_freshVar_60=tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40,tomMatch9NameNumber_end_48);if (tom_is_fun_sym_AttributeNode(tomMatch9NameNumber_freshVar_60)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch9NameNumber_freshVar_60))) {int tomMatch9NameNumber_end_52=tomMatch9NameNumber_end_48 + 1;do {{if (!(tomMatch9NameNumber_end_52 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch9NameNumber_freshVar_65=tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40,tomMatch9NameNumber_end_52);if (tom_is_fun_sym_AttributeNode(tomMatch9NameNumber_freshVar_65)) {if (tom_equal_term_String("Type", tom_get_slot_AttributeNode_Name(tomMatch9NameNumber_freshVar_65))) {if (tom_is_fun_sym_concTNode(tomMatch9NameNumber_freshVar_41)) {if (0 >= tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_41)) {

if (tom_get_slot_AttributeNode_Value(tomMatch9NameNumber_freshVar_37).compareTo(name)==0){result=tom_get_slot_AttributeNode_Value(tomMatch9NameNumber_freshVar_65);}else {getTypeSensors(tom_get_element_concTNode_TNodeList(tomMatch9NameNumber_freshVar_3,tomMatch9NameNumber_end_12).getNextSibling(), name);}}}}}}tomMatch9NameNumber_end_52=tomMatch9NameNumber_end_52 + 1;}} while(!(tomMatch9NameNumber_end_52 > tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40)));}}}tomMatch9NameNumber_end_48=tomMatch9NameNumber_end_48 + 1;}} while(!(tomMatch9NameNumber_end_48 > tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_40)));}}}}tomMatch9NameNumber_end_31=tomMatch9NameNumber_end_31 + 1;}} while(!(tomMatch9NameNumber_end_31 > tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_17)));}}}}tomMatch9NameNumber_end_24=tomMatch9NameNumber_end_24 + 1;}} while(!(tomMatch9NameNumber_end_24 > tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_16)));}}}}tomMatch9NameNumber_end_12=tomMatch9NameNumber_end_12 + 1;}} while(!(tomMatch9NameNumber_end_12 > tom_get_size_concTNode_TNodeList(tomMatch9NameNumber_freshVar_3)));}}}}}}

    	return result;
    }


 /**
	m�thode faisant le mapping entre actuators abstraits et concrets
	
     **/
     public static String actuatorConcreteName(String filename, String nameAbstractActuator){
    	String resultName = "";
    	try {
    		dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
    		Element elementRacine = dom.getDocumentElement();
    		resultName = mapActuators(elementRacine,  nameAbstractActuator);
    	   	return resultName;
        } catch (Exception e){
    		System.out.println("Fichier de mapping introuvable: Actuator " + nameAbstractActuator);
    		return "";
    	}
     }

    private static String mapActuators(Node n,String name){
    	String result="";
    	{{if (tom_is_sort_TNode(n)) {if (tom_is_fun_sym_ElementNode(((org.w3c.dom.Node)n))) { java.util.ArrayList<Node>  tomMatch10NameNumber_freshVar_3=tom_get_slot_ElementNode_ChildList(((org.w3c.dom.Node)n));if (tom_is_fun_sym_concTNode(tom_get_slot_ElementNode_AttrList(((org.w3c.dom.Node)n)))) {if (tom_is_fun_sym_concTNode(tomMatch10NameNumber_freshVar_3)) {int tomMatch10NameNumber_end_12=0;do {{if (!(tomMatch10NameNumber_end_12 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_3))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_18=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_3,tomMatch10NameNumber_end_12);if (tom_is_fun_sym_ElementNode(tomMatch10NameNumber_freshVar_18)) { java.util.ArrayList<Node>  tomMatch10NameNumber_freshVar_16=tom_get_slot_ElementNode_AttrList(tomMatch10NameNumber_freshVar_18); java.util.ArrayList<Node>  tomMatch10NameNumber_freshVar_17=tom_get_slot_ElementNode_ChildList(tomMatch10NameNumber_freshVar_18);if (tom_equal_term_String("actuatorDec", tom_get_slot_ElementNode_Name(tomMatch10NameNumber_freshVar_18))) {if (tom_is_fun_sym_concTNode(tomMatch10NameNumber_freshVar_16)) {int tomMatch10NameNumber_end_24=0;do {{if (!(tomMatch10NameNumber_end_24 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_16))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_37=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_16,tomMatch10NameNumber_end_24);if (tom_is_fun_sym_AttributeNode(tomMatch10NameNumber_freshVar_37)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch10NameNumber_freshVar_37))) {if (tom_is_fun_sym_concTNode(tomMatch10NameNumber_freshVar_17)) {int tomMatch10NameNumber_end_31=0;do {{if (!(tomMatch10NameNumber_end_31 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_17))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_42=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_17,tomMatch10NameNumber_end_31);if (tom_is_fun_sym_ElementNode(tomMatch10NameNumber_freshVar_42)) { java.util.ArrayList<Node>  tomMatch10NameNumber_freshVar_40=tom_get_slot_ElementNode_AttrList(tomMatch10NameNumber_freshVar_42); java.util.ArrayList<Node>  tomMatch10NameNumber_freshVar_41=tom_get_slot_ElementNode_ChildList(tomMatch10NameNumber_freshVar_42);if (tom_equal_term_String("actuatorMap", tom_get_slot_ElementNode_Name(tomMatch10NameNumber_freshVar_42))) {if (tom_is_fun_sym_concTNode(tomMatch10NameNumber_freshVar_40)) {int tomMatch10NameNumber_end_48=0;do {{if (!(tomMatch10NameNumber_end_48 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_64=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40,tomMatch10NameNumber_end_48);if (tom_is_fun_sym_AttributeNode(tomMatch10NameNumber_freshVar_64)) {if (tom_equal_term_String("Left", tom_get_slot_AttributeNode_Name(tomMatch10NameNumber_freshVar_64))) {int tomMatch10NameNumber_end_52=tomMatch10NameNumber_end_48 + 1;do {{if (!(tomMatch10NameNumber_end_52 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_69=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40,tomMatch10NameNumber_end_52);if (tom_is_fun_sym_AttributeNode(tomMatch10NameNumber_freshVar_69)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch10NameNumber_freshVar_69))) { String  tom_n2=tom_get_slot_AttributeNode_Value(tomMatch10NameNumber_freshVar_69);int tomMatch10NameNumber_end_56=tomMatch10NameNumber_end_52 + 1;do {{if (!(tomMatch10NameNumber_end_56 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch10NameNumber_freshVar_74=tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40,tomMatch10NameNumber_end_56);if (tom_is_fun_sym_AttributeNode(tomMatch10NameNumber_freshVar_74)) {if (tom_equal_term_String("Type", tom_get_slot_AttributeNode_Name(tomMatch10NameNumber_freshVar_74))) {if (tom_is_fun_sym_concTNode(tomMatch10NameNumber_freshVar_41)) {if (0 >= tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_41)) {

if (tom_get_slot_AttributeNode_Value(tomMatch10NameNumber_freshVar_37).compareTo(name)==0)
    		{
    		if (tom_get_slot_AttributeNode_Value(tomMatch10NameNumber_freshVar_64).compareTo("false")==0){
    		result="\""+tom_n2+"\""+", false";
    		}
    		else {
    			result="\""+tom_n2+"\""+", true";
    		}	
    		
    		}
    		else {mapActuators(tom_get_element_concTNode_TNodeList(tomMatch10NameNumber_freshVar_3,tomMatch10NameNumber_end_12).getNextSibling(), name);}}}}}}tomMatch10NameNumber_end_56=tomMatch10NameNumber_end_56 + 1;}} while(!(tomMatch10NameNumber_end_56 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40)));}}}tomMatch10NameNumber_end_52=tomMatch10NameNumber_end_52 + 1;}} while(!(tomMatch10NameNumber_end_52 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40)));}}}tomMatch10NameNumber_end_48=tomMatch10NameNumber_end_48 + 1;}} while(!(tomMatch10NameNumber_end_48 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_40)));}}}}tomMatch10NameNumber_end_31=tomMatch10NameNumber_end_31 + 1;}} while(!(tomMatch10NameNumber_end_31 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_17)));}}}}tomMatch10NameNumber_end_24=tomMatch10NameNumber_end_24 + 1;}} while(!(tomMatch10NameNumber_end_24 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_16)));}}}}tomMatch10NameNumber_end_12=tomMatch10NameNumber_end_12 + 1;}} while(!(tomMatch10NameNumber_end_12 > tom_get_size_concTNode_TNodeList(tomMatch10NameNumber_freshVar_3)));}}}}}}

    	return result;
    }

    private static String getTypeActuators(Node n, String name){
        if (n == null) return "";
    	String result = "";
    	{{if (tom_is_sort_TNode(n)) {if (tom_is_fun_sym_ElementNode(((org.w3c.dom.Node)n))) { java.util.ArrayList<Node>  tomMatch11NameNumber_freshVar_3=tom_get_slot_ElementNode_ChildList(((org.w3c.dom.Node)n));if (tom_is_fun_sym_concTNode(tom_get_slot_ElementNode_AttrList(((org.w3c.dom.Node)n)))) {if (tom_is_fun_sym_concTNode(tomMatch11NameNumber_freshVar_3)) {int tomMatch11NameNumber_end_12=0;do {{if (!(tomMatch11NameNumber_end_12 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_3))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_18=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_3,tomMatch11NameNumber_end_12);if (tom_is_fun_sym_ElementNode(tomMatch11NameNumber_freshVar_18)) { java.util.ArrayList<Node>  tomMatch11NameNumber_freshVar_16=tom_get_slot_ElementNode_AttrList(tomMatch11NameNumber_freshVar_18); java.util.ArrayList<Node>  tomMatch11NameNumber_freshVar_17=tom_get_slot_ElementNode_ChildList(tomMatch11NameNumber_freshVar_18);if (tom_equal_term_String("actuatorDec", tom_get_slot_ElementNode_Name(tomMatch11NameNumber_freshVar_18))) {if (tom_is_fun_sym_concTNode(tomMatch11NameNumber_freshVar_16)) {int tomMatch11NameNumber_end_24=0;do {{if (!(tomMatch11NameNumber_end_24 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_16))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_37=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_16,tomMatch11NameNumber_end_24);if (tom_is_fun_sym_AttributeNode(tomMatch11NameNumber_freshVar_37)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch11NameNumber_freshVar_37))) {if (tom_is_fun_sym_concTNode(tomMatch11NameNumber_freshVar_17)) {int tomMatch11NameNumber_end_31=0;do {{if (!(tomMatch11NameNumber_end_31 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_17))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_42=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_17,tomMatch11NameNumber_end_31);if (tom_is_fun_sym_ElementNode(tomMatch11NameNumber_freshVar_42)) { java.util.ArrayList<Node>  tomMatch11NameNumber_freshVar_40=tom_get_slot_ElementNode_AttrList(tomMatch11NameNumber_freshVar_42); java.util.ArrayList<Node>  tomMatch11NameNumber_freshVar_41=tom_get_slot_ElementNode_ChildList(tomMatch11NameNumber_freshVar_42);if (tom_equal_term_String("actuatorMap", tom_get_slot_ElementNode_Name(tomMatch11NameNumber_freshVar_42))) {if (tom_is_fun_sym_concTNode(tomMatch11NameNumber_freshVar_40)) {int tomMatch11NameNumber_end_48=0;do {{if (!(tomMatch11NameNumber_end_48 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_64=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40,tomMatch11NameNumber_end_48);if (tom_is_fun_sym_AttributeNode(tomMatch11NameNumber_freshVar_64)) {if (tom_equal_term_String("Left", tom_get_slot_AttributeNode_Name(tomMatch11NameNumber_freshVar_64))) {int tomMatch11NameNumber_end_52=tomMatch11NameNumber_end_48 + 1;do {{if (!(tomMatch11NameNumber_end_52 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_69=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40,tomMatch11NameNumber_end_52);if (tom_is_fun_sym_AttributeNode(tomMatch11NameNumber_freshVar_69)) {if (tom_equal_term_String("Name", tom_get_slot_AttributeNode_Name(tomMatch11NameNumber_freshVar_69))) {int tomMatch11NameNumber_end_56=tomMatch11NameNumber_end_52 + 1;do {{if (!(tomMatch11NameNumber_end_56 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40))) {org.w3c.dom.Node tomMatch11NameNumber_freshVar_74=tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40,tomMatch11NameNumber_end_56);if (tom_is_fun_sym_AttributeNode(tomMatch11NameNumber_freshVar_74)) {if (tom_equal_term_String("Type", tom_get_slot_AttributeNode_Name(tomMatch11NameNumber_freshVar_74))) {if (tom_is_fun_sym_concTNode(tomMatch11NameNumber_freshVar_41)) {if (0 >= tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_41)) {

if (tom_get_slot_AttributeNode_Value(tomMatch11NameNumber_freshVar_37).compareTo(name)==0){result=tom_get_slot_AttributeNode_Value(tomMatch11NameNumber_freshVar_74);}else {getTypeActuators(tom_get_element_concTNode_TNodeList(tomMatch11NameNumber_freshVar_3,tomMatch11NameNumber_end_12).getNextSibling(), name);}}}}}}tomMatch11NameNumber_end_56=tomMatch11NameNumber_end_56 + 1;}} while(!(tomMatch11NameNumber_end_56 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40)));}}}tomMatch11NameNumber_end_52=tomMatch11NameNumber_end_52 + 1;}} while(!(tomMatch11NameNumber_end_52 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40)));}}}tomMatch11NameNumber_end_48=tomMatch11NameNumber_end_48 + 1;}} while(!(tomMatch11NameNumber_end_48 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_40)));}}}}tomMatch11NameNumber_end_31=tomMatch11NameNumber_end_31 + 1;}} while(!(tomMatch11NameNumber_end_31 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_17)));}}}}tomMatch11NameNumber_end_24=tomMatch11NameNumber_end_24 + 1;}} while(!(tomMatch11NameNumber_end_24 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_16)));}}}}tomMatch11NameNumber_end_12=tomMatch11NameNumber_end_12 + 1;}} while(!(tomMatch11NameNumber_end_12 > tom_get_size_concTNode_TNodeList(tomMatch11NameNumber_freshVar_3)));}}}}}}

    	return result;
    }

    

    public static void copyFileFSM (String destPath)  {
    	try {
    		String dest=destPath+"/fsm.u"; 
    		File destFile=new File(dest);
    	
    		BufferedReader in = Activator.getDefault().openFile("resources/fsm.u");
    		//BufferedReader in = new BufferedReader(new FileReader("resources/fsm.u"));
    		BufferedWriter out=new BufferedWriter(new FileWriter(destFile));
    		
    		char[] buf = new char[4096];
    		int n;
    		while ((n=in.read(buf, 0, buf.length)) > 0)
    		out.write(buf, 0, n);

    		in.close();
    		out.close();
    	}

    	catch (IOException e){
    		e.printStackTrace();
        }
    }


    private static String replaceString(String chaine, List<String> nameList, String str){
         String result = chaine;
         for(String s : nameList){
             result = result.replace(s, s + "." + str);
         }
         return result;
    }

    private static List<String> getListSensorName(Mission mission){
        List<String> result = new ArrayList<String>();
        for(Sensor s : mission.getSensor()){
            result.add(s.getName());
        }
        return result;
    }

    private static List<String> getListActuatorName(Mission mission){
        List<String> result = new ArrayList<String>();
        for(Actuator act : mission.getActuator()){
           String typeAct = getTypeActuators(getElementRacineFileMapping(fileMapping), act.getName());
           if(typeAct.equals("DifferentialWheels")) 
              result.add(act.getName());
        }
        return result;
    }

    public static Element getElementRacineFileMapping(String filename){
    	try {
    		dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
    		Element elementRacine = dom.getDocumentElement();
    	   	return elementRacine;
        } catch (Exception e){
    		System.out.println("Fichier de mapping " + filename + " introuvable: ");
    		return null;
    	}
     }



}

